/******************************************************************************
 *      Mestrado em Ciência da Computação - UFMS
 *		Redes de Computadores - Prof. Dr. Ronaldo Alves Ferreira
 *		Alunos: Geraldo Landre, Marcel Tolentino, Vinícius Bueno
 *****************************************************************************/
/* tcpsndlen.c - tcpsndlen */

#include "tcpfms.h"
#include "tcb.h"
#include "tcp.h"


/*------------------------------------------------------------------------
 *  tcpsndlen - compute the packet length and offset in sndbuf
 *------------------------------------------------------------------------
 */
int tcpsndlen(struct tcb *ptcb, int rexmt, unsigned int *poff)
{
	unsigned datalen;

	if (rexmt || (ptcb->tcb_code & TCPF_SYN))
            *poff = 0;
	else
            *poff = ptcb->tcb_snext - ptcb->tcb_suna;
	datalen = ptcb->tcb_sbcount - *poff;
	datalen = min(datalen, ptcb->tcb_swindow);
	return min(datalen, ptcb->tcb_smss);
}